package com.xbx.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xbx.commonutils.R;
import com.xbx.eduservice.entity.EduCourse;
import com.xbx.eduservice.entity.EduTeacher;
import com.xbx.eduservice.service.EduCourseService;
import com.xbx.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/eduservice/indexfront")
public class EduFrontController {
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;
    @GetMapping("index")
    public R index(){
        //查询8条热门课程，和前四条名师
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> eduCourseList=eduCourseService.list(wrapper);
        QueryWrapper<EduTeacher> eduTeacherQueryWrapper=new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("id");
        eduTeacherQueryWrapper.last("limit 2");
        List<EduTeacher> eduTeacherList=eduTeacherService.list(eduTeacherQueryWrapper);
        return R.ok().data("courseList",eduCourseList).data("teacherList",eduTeacherList);

    }
}
